<?php
$this->load->model('services_model');
?>

<script type="text/javascript" src="<?php echo base_url(); ?>static/select2/select2.min.js" ></script>
<script type="text/javascript" src="<?php echo base_url(); ?>static/js/selectSearchGlobal.js"></script>



<?php
$vDate   =date("d/m/Y");
$vHour   =date("H");
$vMinute =date("i");
 
	foreach($getMonitoringCount as $a){   
	    $row=$a["CNT_ROW"];
 	}
    
    //echo $row; exit;
?>

<div id="tablecontent" class="col-md-12">						
                        <div class="form-group">
                            <div class="table-responsive">
                                <table class="table table-bordered table-condensed table-striped" style="background:#f9f9f9;">
                                    <thead>
                                        <tr>
                                            <th class="tblhead" style="width:10%;text-align:center;">No</th>
                                            <th class="tblhead" style="width:10%;text-align:center;">Item</th>
                                            <th class="tblhead" style="width:10%;text-align:center;">Uom</th>
                                            <th class="tblhead" style="width:10%;text-align:center;">Qty</th>
                                            <th class="tblhead" style="width:10%;text-align:center;">Price</th>
                                            <th class="tblhead" style="width:10%;text-align:center;">Total Price</th>
                                            <th class="tblhead" style="width:10%;text-align:center;">Need By Date</th>
                                            <th class="tblhead" style="width:10%;text-align:center;">Mitra</th>
                                            <th class="tblhead" style="width:10%;text-align:center;">PR No</th>
                                            <th class="tblhead" style="width:10%;text-align:center;">OF No</th>
                                            <th class="tblhead" style="width:%;text-align:center;">Item Delivery</th>
                                            <th class="tblhead" style="width:%;text-align:center;">Status</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                    <?php
                                    if (empty($row)) {
                                        ?>
                                        <tr><td colspan="8" style="text-align:center">No Data Available</td></tr>
                                        <?php
                                    } 
                                    else if($row>0){
                                        $i=0;
                                        foreach($getMonitoring as $a){
                                            $aPrmRequisitionId 		= $a["PRM_REQUISITION_ID"];
                                			$aPrdItemDescription   	= $a["PRD_ITEM_DESCRIPTION"];
                                			$aPrdId            		= $a["PRD_DET_ID"];
                                			$aPrmLastUpdateBy  		= $a["PRM_LAST_UPDATE_BY"];
                                			$aPrmLastUpdateDate		= $a["PRM_LAST_UPDATE_DATE"];
                                			$aVendorId		   		= $a["VENDOR_ID"];
                                			$aVendorSiteId     		= $a["VENDOR_SITE_ID"];
                                			$aFomId		   	   		= $a["FOM_ID"];
                                			$aPrdUom           		= $a["PRD_UOM"];
                                			$aPrdQuantity      		= $a["PRD_QUANTITY"];
                                			$aPrdUnitPrice     		= $a["PRD_UNIT_PRICE"];
                                			$aPrdTotalPrice    		= $a["PRD_TOTAL_PRICE"];
                                			$aPrdNeedByDate    		= $a["PRD_NEED_BY_DATE"];
                                			$aPrdDmrStatus     		= $a["PRD_DMR_STATUS"];
                                			$aPrdDetID         		= $a["PRD_DET_ID"];
                                			$aPrdItemBy        		= $a["PRD_ITEM_STATUS_BY"];
                                			$aExpired          		= $a["EXPIRED"];
                                			//$aVendorName = dbora_getvendor($aVendorId);
                                            
                                			/* QUERY INI MASIH SALAH
                                            $qrydetitem="select nvl(sum(prdi_qty),0) prdi_qty from lkk_pr_det_item where prd_det_id = $aPrdId and prm_requisition_id = $aPrmRequisitionId ";
                                			$DB3->parse($qrydetitem);
                                			$DB3->execute();		
                                			$bPrdiQty = ($b=$DB3->nextrow()) ? $bPrdiQty = $b["PRDI_QTY"] : "";
                                            */
                                            
                                			$status = "";
                                			if($aExpired > 0) {
                                    			if(empty($aPrdDmrStatus)) {
                                                    $status = "New";
                                    			}
                                                else if($aPrdQuantity == $bPrdiQty && !empty($aPrdDmrStatus)) {
                                                    $status = "Full";
                                    			}
                                                else if($aPrdQuantity > $bPrdiQty && !empty($aPrdDmrStatus)) {
                                                    $status = "Partial";
                                    			}
                                			}
                                            else {
                                    			if($aPrdQuantity == $bPrdiQty && !empty($aPrdDmrStatus)) {
                                        			$status = "Full";
                                    			}
                                                else {
                                                    $status = "Outstanding";
                                    			}
                                			}
                                			//$classname = $classname=='even'?'odd':'even';
                                            
                                            ?>
                                            <tr>
                                                <td style="font-size:10px;"><?php echo $i+1;?></td>
                                                <td style="font-size:10px;"><?php echo $aPrdItemDescription;?></td>
                                                <td style="font-size:10px;"><?php echo $aPrdUom;?></td>
                                                <td style="font-size:10px;"><?php echo $aPrdQuantity;?></td>
                                                <td style="font-size:10px;"><?php echo $aPrdUnitPrice;?></td>
                                                <td style="font-size:10px;"><?php echo $aPrdTotalPrice;?></td>
                                                <td style="font-size:10px;"><?php echo $aPrdNeedByDate;?></td>
                                                <td style="font-size:10px;"><?php echo $aVendorName;?></td>
                                                <td style="font-size:10px;"><?php echo $aPrmRequisitionId;?></td>
                                                <td style="font-size:10px;"><?php echo $aFomId;?></td>
                                                <td style="font-size:10px;"><?php echo $bPrdiQty;?></td>
                                                <td style="font-size:10px;"><?php echo $status;?></td>
                                            </tr>
                                            <?php
                                            $i++;
                                        }    
                                    }
                                    ?>
                                            
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <div class="form-group">
                            <div id="mypaging">
                                <?php
                                echo $paging;
                                echo $jump_page;
                                echo $ipp;
                                ?>
                            </div>								
                        </div>						
                    </div>
